//
//  MyButton.m
//  时光电影项目
//
//  Created by 墨狂之逸才 on 15/7/17.
//  Copyright (c) 2015年 墨狂之逸才. All rights reserved.
//

#import "MyButton.h"

@implementation MyButton

- (id)initWithFrame:(CGRect)frame withImageName:(NSString *)imageName withTitle:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        
        imageView = [[UIImageView alloc]initWithFrame:CGRectZero];

//        imageView.image = [UIImage imageNamed:imageName];
        [imageView setImage:[UIImage imageNamed:imageName]];
//        imageView.
        [self addSubview:imageView];
        
        
        label = [[UILabel alloc]initWithFrame:CGRectZero];
        label.text = title;
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:14];
        [self addSubview:label];
        
    }
    return self;
}


//当被加到别的view的时候，宽高改变的时候［self setNeedLayOut］告诉系统。需要重新布局视图
//一般这个方法都是写在哪里的？
- (void)layoutSubviews
{
    
    imageView.frame = CGRectMake((CGRectGetWidth(self.frame)-20)/2, 5, 20, 20);
    label.frame = CGRectMake(0, CGRectGetMaxY(imageView.frame), self.frame.size.width, 20);
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
